home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
576-600
/
581
/
prism
/
source
/
source.lzh
/
prism.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-06
|
47KB
|
1,621 lines
/***********************************************************************\
* Prism - THE Amiga ANSI Animator *
* By: Colin Vernon *
* Prism 1.00 - October 15,1989 *
* *
* Version 1.2 by Chris Timmerberg, 10/01/90 *
* New improved load routine, handles more esc seq, and handles the rest *
* better. Sprite definitions were given CHIP keyword, no longer needed *
* to copy to Chip. For some reason BackStdOut didnt work so I replaced *
* with opening a new window. Now uses function prototypes for smaller/ *
* faster code. Fixed so it actually works on my computer. Not sure what *
* that one was! *
* *
* Version 1.3 by Chris Timmerberg, 01/31/91 *
* Fixed save problems relating to intensity, & improved save efficiency *
* Eliminated some redundant assignments as suggested by global optimizer*
* *
* Version 1.3I by Chris Timmerberg, 03/31/91 *
* Bumped line count up to 25 (WHY did Colin have 24 lines???) Interlace *
* (50 line) mode added for those users of my other program, toans. Went *
* through and replaced chars with UBYTES and (most) ints with USHORTS. *
* Removed a ^ on line 1060. Still not sure why Colin had it there. *
* *
* Version 1.4 by Syd L. Bolton, 11/16/91 *
* Changed to a totally different File Requester, which allows VOLUME *
* names to be clicked on. Re-wrote a good chunk of the source code to *
* make it MUCH more readable. Also cut down source size because a lot *
* of the White-Space was SPACES instead of TABS. Made some changes so *
* that it would compile under Manx 5.0 (only needed to change the *
* #includes, and put feof in the load routine). Added the configure menu*
* and the menus to choose SPEED EMULATION (2400 baud, 1200 baud, etc.) *
* Also made it optional to put a CLEAR at the beginning of the file (in *
* case you're doing an animation that already has stuff on the screen) *
* Added a new gadget at the bottom that allows you to constantly be in *
* BACKGROUND COLOR mode, in case you change your BG color a lot. *
\***********************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <functions.h>
#include <libraries/dos.h>
#include <exec/exec.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <graphics/sprite.h>
#define MAXWIDTH 80
#define MINHEIGHT 1
#define MINWIDTH 1
#define MAXCHARSETS 12
#define SPACE 0x20
#define BACKSPACE 0x08
#define LINEFEED 0x0a
#define FORMFEED 0x0c
#define RETURN 0x0d
#define TAB 0x09
#define CURSOR_UP 'A'
#define CURSOR_DOWN 'B'
#define CURSOR_RIGHT 'C'
#define CURSOR_LEFT 'D'
#define ESC 0x1b
#define MAXINPUTLEN 80
struct ANSI {
struct ANSI *next;
struct ANSI *previous;
UBYTE x,y,fcolor,bcolor,letter,pad;
};
static UBYTE Titlebar[] = "Prism 1.4 by Syd L. Bolton, Chris Timmerberg, original by Colin Vernon";
struct DOSBase *DOSBase;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct DiskfontBase *DiskfontBase;
struct Screen *WorkScreen;
struct Window *WorkWindow;
struct Window *Gads;
struct Window *ReqWindow;
struct IntuiMessage *message;
struct IOStdReq ioStdReq;
struct Library *ConsoleDevice = 0;
struct SimpleSprite Cursor;
struct RastPort *rport;
/************************** Sprite Defs *********************************/
UWORD NormalCursor[] = {
0,0,
0xf000,0xf000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xf000,0xf000,
0,0
};
UWORD InterlaceCursor[]= {
0,0,
0xf000,0xf000,0x0000,0x0000,0x0000,0x0000,0xf000,0xf000,
0,0
};
UWORD ChipBlank[] ={
0,0,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0,0
};
WORD Spr1;
/*************************** Gadget Definitions **************************/
struct IntuiText Color15 ={0,15,JAM2,0,0,0," 15 ",0,};
struct IntuiText Color14 ={0,14,JAM2,0,0,0," 14 ",0,};
struct IntuiText Color13 ={0,13,JAM2,0,0,0," 13 ",0,};
struct IntuiText Color12 ={0,12,JAM2,0,0,0," 12 ",0,};
struct IntuiText Color11 ={0,11,JAM2,0,0,0," 11 ",0,};
struct IntuiText Color10 ={0,10,JAM2,0,0,0," 10 ",0,};
struct IntuiText Color9 ={0,9,JAM2,0,0,0," 9 ",0,};
struct IntuiText Color8 ={0,8,JAM2,0,0,0," 8 ",0,};
struct IntuiText Color7 ={0,7,JAM2,0,0,0," 7 ",0,};
struct IntuiText Color6 ={0,6,JAM2,0,0,0," 6 ",0,};
struct IntuiText Color5 ={0,5,JAM2,0,0,0," 5 ",0,};
struct IntuiText Color4 ={0,4,JAM2,0,0,0," 4 ",0,};
struct IntuiText Color3 ={0,3,JAM2,0,0,0," 3 ",0,};
struct IntuiText Color2 ={0,2,JAM2,0,0,0," 2 ",0,};
struct IntuiText Color1 ={0,1,JAM2,0,0,0," 1 ",0,};
struct IntuiText Color0 ={1,0,JAM2,0,0,0," 0 ",0,};
struct IntuiText ForeBack2 = {
15,0,JAM2,7,10,0,(UBYTE *)"Col",0
};
struct IntuiText ForeBackText = {
15,0,JAM2,3,2,0,(UBYTE *)"Back",&ForeBack2
};
struct Gadget ForeBackGadget = {
0,553,10,38,19,
GADGHCOMP | SELECTED,RELVERIFY,BOOLGADGET,
0,0,&ForeBackText,0,0,17,0
};
struct IntuiText FBStickText = {
15,0,JAM2,3,6,0,(UBYTE *)"Fore",0
};
struct Gadget FBStickGadget = {
&ForeBackGadget,597,10,38,19,
GADGHCOMP|SELECTED,RELVERIFY,BOOLGADGET,
0,0,&FBStickText,0,0,18,0
};
struct Gadget SelColor15 = {
&FBStickGadget,512,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color15,0,0,16,0
};
struct Gadget SelColor14 = {
&SelColor15,478,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color14,0,0,15,0
};
struct Gadget SelColor13 = {
&SelColor14,444,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color13,0,0,14,0
};
struct Gadget SelColor12 = {
&SelColor13,410,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color12,0,0,13,0
};
struct Gadget SelColor11 = {
&SelColor12,376,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color11,0,0,12,0
};
struct Gadget SelColor10 = {
&SelColor11,342,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color10,0,0,11,0
};
struct Gadget SelColor9 = {
&SelColor10,308,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color9,0,0,10,0
};
struct Gadget SelColor8 = {
&SelColor9,274,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color8,0,0,9,0
};
struct Gadget SelColor7 = {
&SelColor8,240,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color7,0,0,8,0
};
struct Gadget SelColor6 = {
&SelColor7,206,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color6,0,0,7,0
};
struct Gadget SelColor5 = {
&SelColor6,172,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color5,0,0,6,0
};
struct Gadget SelColor4 = {
&SelColor5,138,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color4,0,0,5,0
};
struct Gadget SelColor3 = {
&SelColor4,104,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color3,0,0,4,0
};
struct Gadget SelColor2 = {
&SelColor3,70,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color2,0,0,3,0
};
struct Gadget SelColor1 = {
&SelColor2,36,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color1,0,0,2,0
};
struct Gadget SelColor0 = {
&SelColor1,2,11,32,8,
GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,
0,0,&Color0,0,0,1,0
};
/**** REQUESTERS ****/
struct IntuiText AboutProg7Text = {
4,7,JAM2,30,59,0,"Syd Bolton of Legendary Design Technologies Inc.",0
};
struct IntuiText AboutProg6Text = {
4,7,JAM2,30,50,0,"Enhancements to this program by Chris Timmerberg, and",&AboutProg7Text
};
struct IntuiText AboutProg5Text = {
4,7,JAM2,30,41,0,"are not modified. This version of Prism is public domain.",&AboutProg6Text
};
struct IntuiText AboutProg4Text = {
4,7,JAM2,30,32,0,"distributed as long as the original files in the archive",&AboutProg5Text
};
struct IntuiText AboutProg3Text = {
4,7,JAM2,30,23,0,"Prism is an ANSI animator for the Amiga. It can be",&AboutProg4Text
};
struct IntuiText AboutProgText = {
1,7,JAM1,205,9,0,"Prism by Colin Vernon",&AboutProg3Text
};
/***** The Requester Window *****/
struct NewWindow RequesterWindow = {
135,50,370,100,0,7,GADGETUP,SIMPLE_REFRESH|ACTIVATE,0,0,0,0,0,0,0,0,0,
CUSTOMSCREEN,
};
struct Requester FileSelectBox;
struct TextAttr WorkFont = {
(STRPTR)"ibm.font",
8,0,0
};
struct TextAttr DisplayFont = {
(STRPTR)"topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT
};
struct NewScreen FirstWorkScreen = {
0,0,640,210,4,4,7,HIRES|SPRITES,CUSTOMSCREEN,&DisplayFont,Titlebar,0,0
};
struct NewWindow FirstWorkWindow = {
0,10,640,200,4,7,MOUSEBUTTONS|RAWKEY|MENUPICK,
SMART_REFRESH|ACTIVATE|BORDERLESS|GIMMEZEROZERO,
0,0,0,0,0,0,0,0,0,CUSTOMSCREEN
};
struct NewWindow GadgetWindow = {
0,170,640,30,4,7,GADGETUP|ACTIVEWINDOW,SMART_REFRESH|WINDOWDRAG,
&SelColor0,0,"Gadget Box",0,0,0,0,0,0,CUSTOMSCREEN
};
struct InputEvent inputEvent = {
0,IECLASS_RAWKEY,0,0,0
};
UWORD AtrColors[16] = {
0x000, 0xA00, 0x0A0, 0xA60, 0x00A, 0xA0A, 0x0AA, 0xBBB,
0x666, 0xF00, 0x0F0, 0xFF0, 0x00F, 0xF0F, 0x0FF, 0xFFF
};
/**************************** Menu Definition **************************/
struct IntuiText ForplanesText = {4,7,JAM2,18,1,&DisplayFont,"16 Colors",0};
struct IntuiText ThreeplanesText = {4,7,JAM2,18,1,&DisplayFont,"8 Colors",0};
struct IntuiText TwoplanesText = {4,7,JAM2,18,1,&DisplayFont,"4 Colors",0};
struct IntuiText ColorsText = {4,7,JAM2,0,1,&DisplayFont,"Colors >",0};
struct IntuiText QuitText = {4,7,JAM2,0,1,&DisplayFont,"Quit",0};
struct IntuiText AppendText = {4,7,JAM2,0,1,&DisplayFont,"Append >",0};
struct IntuiText SaveText = {4,7,JAM2,0,1,&DisplayFont,"Save...",0};
struct IntuiText LoadText = {4,7,JAM2,0,1,&DisplayFont,"Load...",0};
struct IntuiText ClearText = {4,7,JAM2,0,1,&DisplayFont,"Clear",0};
struct IntuiText PlaybackText = {4,7,JAM2,0,1,&DisplayFont,"Playback",0};
struct IntuiText AboutText = {4,7,JAM2,0,1,&DisplayFont,"About",0};
struct IntuiText InterlaceText = {4,7,JAM2,18,1,&DisplayFont,"Lace",0};
struct IntuiText ConfigText = {4,7,JAM2,0,1,&DisplayFont,"Configure...",0};
struct IntuiText TFBaudText = {4,7,JAM2,18,1,&DisplayFont,"2400 Baud",0};
struct IntuiText TWBaudText = {4,7,JAM2,18,1,&DisplayFont,"1200 Baud",0};
struct IntuiText FastestText = {4,7,JAM2,18,1,&DisplayFont,"FASTEST",0};
struct IntuiText SpeedText = {4,7,JAM2,0,1,&DisplayFont,"Speed >",0};
struct IntuiText SClearText = {4,7,JAM2,18,1,&DisplayFont,"SClear",0};
struct MenuItem Configure = {
0,0,40,110,10,ITEMTEXT|ITEMENABLED|HIGHCOMP,0,(APTR)&ConfigText,0,0,0,0
};
struct MenuItem SClear = {
&Configure,0,30,110,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT|COMMSEQ,0,
(APTR)&SClearText,0,'R',0,0
};
struct MenuItem Interlace = {
&SClear,0,20,110,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ|CHECKIT, 0,
(APTR)&InterlaceText,0,'I',0,0
};
struct MenuItem Fastest = {
0,80,20,100,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT|CHECKED,
3,(APTR)&FastestText,0,0,0,0
};
struct MenuItem TFBaud = {
&Fastest,80,10,100,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
5,(APTR)&TFBaudText,0,0,0,0
};
struct MenuItem TWBaud = {
&TFBaud,80,0,100,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT,
5,(APTR)&TWBaudText,0,0,0,0
};
struct MenuItem Speed ={
&Interlace,0,10,110,10,ITEMTEXT|ITEMENABLED|HIGHCOMP,0,
(APTR)&SpeedText,0,0,&TWBaud,0
};
struct MenuItem Forplanes = {
0,80,20,130,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ|
CHECKIT|CHECKED,3,(APTR)&ForplanesText,0,'4',0,0
};
struct MenuItem Threeplanes = {
&Forplanes,80,10,130,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ|
CHECKIT,5,(APTR)&ThreeplanesText,0,'3',0,0
};
struct MenuItem Twoplanes = {
&Threeplanes,80,0,130,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ|
CHECKIT,6,(APTR)&TwoplanesText,0,'2',0,0
};
struct MenuItem Colors ={
&Speed,0,0,110,10,ITEMTEXT|ITEMENABLED|HIGHCOMP,0,
(APTR)&ColorsText,0,0,&Twoplanes,0
};
struct MenuItem Quit = {
0,0,60,120,10,ITEMTEXT|ITEMENABLED|HIGHBOX|COMMSEQ,0,
(APTR)&QuitText,0,'Q',0,0
};
struct MenuItem AppSave = {
0,80,10,60,10,ITEMTEXT|ITEMENABLED|HIGHCOMP,0,
(APTR)&SaveText,0,0,0,0
};
struct MenuItem AppLoad = {
&AppSave,80,0,60,10,ITEMTEXT|ITEMENABLED|HIGHCOMP,0,
(APTR)&LoadText,0,0,0,0
};
struct MenuItem Append = {
&Quit,0,50,120,10,ITEMTEXT|ITEMENABLED|HIGHCOMP,0,
(APTR)&AppendText,0,0,&AppLoad,0
};
struct MenuItem Save = {
&Append,0,40,120,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,0,
(APTR)&SaveText,0,'S',0,0
};
struct MenuItem Load = {
&Save,0,30,120,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,0,
(APTR)&LoadText,0,'L',0,0
};
struct MenuItem Clear = {
&Load,0,20,120,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,0,
(APTR)&ClearText,0,'C',0,0
};
struct MenuItem Playback = {
&Clear,0,10,120,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,0,
(APTR)&PlaybackText,0,'P',0,0
};
struct MenuItem About = {
&Playback,0,0,120,10,ITEMTEXT|ITEMENABLED|HIGHCOMP,0,
(APTR)&AboutText,0,0,0,0
};
struct Menu Setup = {
0,100,0,100,10,MENUENABLED,"Setup",&Colors
};
struct Menu Project = {
&Setup,0,0,100,10,MENUENABLED,"Project",&About
};
UBYTE Buffer[MAXINPUTLEN];
USHORT scanner;
struct ANSI storage = { 0,0,-1,-1,-1,-1,0 };
struct ANSI *sdlstptr, *lastptr, *middle, *front, *back;
struct TextFont *TFont;
USHORT length = 0,position = 0; /* used to display where editor is */
USHORT cx = 1, cy = 1; /* cursor co-ordinates */
USHORT maxheight=25;
BOOL changes = FALSE;
static UBYTE funckey[MAXCHARSETS][8] = {
{0xb3, 0xc4, 0xc5, 0xc0, 0xd9, 0xda, 0xbf, 0xd8},
{0xba, 0xcd, 0xce, 0xc8, 0xbc, 0xc9, 0xbb, 0xd7},
{0xc1, 0xc2, 0xb4, 0xc3, 0xca, 0xcb, 0xb9, 0xcc},
{0xbe, 0xd4, 0xb8, 0xd5, 0xbd, 0xd3, 0xb7, 0xd6},
{0xd0, 0xd2, 0xb6, 0xc7, 0xcf, 0xd1, 0xb5, 0xc6},
{0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xb0, 0xb1, 0xb2},
{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7},
{0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7},
{0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef},
{0xf0, 0xf1, 0xf2, 0xf3, 0xfe, 0xf6, 0xfd, 0xfb},
{0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf},
{0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfc}
};
UBYTE path[512] = "";
UBYTE filename[33] = "Unnamed.ans";
long _stack = 10000; /* my Load-And-Stay Resident stack size */
UBYTE *_procname = "Prism"; /* my proceedure name */
long _priority = 0; /* A regular priority */
long _BackGroundIO = 0; /* If this != 0, I can Write() to CLI but
I must Close(_Backstdout) when done */
extern BPTR _Backstdout; /* CLI file handle */
struct IntuiText GeneralText = {
1,0,JAM2,0,0,&WorkFont,Buffer,0
};
int windowtopedge,windowleftedge,dir_only=0,read_dir=1; /* new to 1.4 */
int cmode=0,sclearmode=1,lacemode=0,tabspace=8,speed=0,maxcolor=15;
#include "pointer.c"
main()
{
ULONG MessageClass;
USHORT code, qualifier;
UBYTE memusestr[81]; /* display position and length */
SHORT mx, my; /* mouse co-ordinates */
USHORT fcolor = 7; /* initialize forground color */
USHORT bcolor = 0;
USHORT tabplace, tempnum, jx, jy;
SHORT presset = 0;
BOOL mbuttons = FALSE, BGmode = FALSE, gadwinfront = TRUE;
struct Gadget *GadgetPtr;
USHORT GadgetID;
load_config();
OpenLibs();
lastptr = &storage;
middle = lastptr;
FOREVER {
mx = (SHORT) (WorkWindow->GZZMouseX)/8+1;
my = (SHORT) (WorkWindow->GZZMouseY)/8+1;
if (cx >= MINWIDTH && cx <= MAXWIDTH && cy >= MINHEIGHT && cy <= maxheight) {
jx = (cx-1)*8-2;
jy = (cy-1)*8+FirstWorkWindow.TopEdge;
MoveSprite(&WorkScreen->ViewPort,&Cursor,jx,jy);
}
if (message = (struct IntuiMessage *)GetMsg(WorkWindow->UserPort)) {
MessageClass = message->Class;
code = message->Code;
qualifier = message->Qualifier;
ReplyMsg(message);
if (MessageClass & MOUSEBUTTONS) {
switch (code) {
case SELECTDOWN: mbuttons = TRUE;
break;
case SELECTUP: mbuttons = FALSE;
break;
}
}
else switch (MessageClass) {
case RAWKEY: if (!(code & IECODE_UP_PREFIX)) {
inputEvent.ie_Code = code;
inputEvent.ie_Qualifier = qualifier;
scanner = RawKeyConvert(&inputEvent,Buffer,MAXINPUTLEN,0);
Buffer[scanner] = 0;
if (Buffer[0]==0x9b && scanner>1) {
switch (Buffer[1]) {
case CURSOR_UP: cy--;
if (cy < MINHEIGHT) cy = MINHEIGHT;
break;
case CURSOR_DOWN: cy++;
if (cy > maxheight) cy = maxheight;
break;
case CURSOR_LEFT: if (qualifier & IEQUALIFIER_CONTROL) {
if (middle != 0 && middle != &storage) {
back = middle;
tempnum = 1;
while (back != 0 && back != &storage && tempnum == 1) {
back=back->previous;
if (middle->x == back->x && middle->y == back->y) {
memusestr[0]=back->letter;
memusestr[1]=0;
ColorTextXY(WorkWindow,memusestr,back->x,back->y,back->fcolor,back->bcolor);
tempnum = 0;
}
}
if (back==0 || back==&storage) {
memusestr[0] = SPACE;
memusestr[1] = 0;
ColorTextXY(WorkWindow,memusestr,middle->x,middle->y,1,0);
}
middle=middle->previous;
if (middle != &storage) {
cx = middle->x;
cy = middle->y;
}
else {
cx = MINWIDTH;
cy = MINHEIGHT;
}
--position;
}
}
else {
cx--;
if (cx < MINWIDTH) cx = MINWIDTH;
}
break;
case CURSOR_RIGHT: if (qualifier & IEQUALIFIER_CONTROL) {
if (middle != 0) {
if (middle->next != 0) {
middle=middle->next;
cx = middle->x; cy = middle->y;
++position;
}
memusestr[0]=middle->letter;
memusestr[1]=0;
ColorTextXY(WorkWindow,memusestr,middle->x,middle->y,middle->fcolor,middle->bcolor);
}
}
else {
cx++;
if (cx > MAXWIDTH) cx = MAXWIDTH;
}
break;
default: if (scanner == 3 && Buffer[2] == '~') {
if (Buffer[1] == '?') {
if (gadwinfront) {
WindowToBack(Gads);
gadwinfront = FALSE;
}
else {
WindowToFront(Gads);
gadwinfront = TRUE;
}
break;
}
Buffer[2] = 0;
tempnum = atoi(&Buffer[1]);
Buffer[2] = '~';
if (tempnum >= 0 && tempnum <= 7) {
Buffer[0] = funckey[presset][tempnum];
Buffer[1] = 0;
scanner = 1;
}
if (tempnum == 8) {
++presset;
if (presset > MAXCHARSETS-1) presset = 0;
}
if (tempnum == 9) {
--presset;
if (presset < 0) presset = MAXCHARSETS-1;
}
}
}
}
if (scanner > 0 && Buffer[0] != 0x9b) {
switch (Buffer[0]) {
case RETURN: cx = MINWIDTH;
cy++;
if (cy > maxheight) cy = maxheight;
break;
case BACKSPACE: if (lastptr == &storage || middle == &storage) break;
back = middle;
tempnum = 1;
while (back != 0 && back != &storage && tempnum == 1) {
back=back->previous;
if (middle->x == back->x && middle->y == back->y) {
memusestr[0]=back->letter;
memusestr[1]=0;
ColorTextXY(WorkWindow,memusestr,back->x,back->y,back->fcolor,back->bcolor);
tempnum = 0;
}
}
if (back==0 || back==&storage) {
memusestr[0] = SPACE;
memusestr[1] = 0;
ColorTextXY(WorkWindow,memusestr,middle->x,middle->y,1,0);
}
if (middle->next == 0) {
free((UBYTE *)lastptr);
lastptr = sdlstptr;
sdlstptr = sdlstptr->previous;
lastptr->next = 0;
memusestr[0] = lastptr->letter;
memusestr[1] = 0;
if (lastptr != &storage) {
ColorTextXY(WorkWindow,memusestr,lastptr->x,lastptr->y,lastptr->fcolor,lastptr->bcolor);
cx = lastptr->x; cy = lastptr->y;
}
middle = lastptr;
}
else {
for (back = middle, front = back->next; front != 0; back=back->next, front = back->next) {
back->fcolor = front->fcolor;
back->bcolor = front->bcolor;
back->x = front->x;
back->y = front->y;
back->letter = front->letter;
}
free((UBYTE *)lastptr);
lastptr = sdlstptr;
sdlstptr = sdlstptr->previous;
lastptr->next = 0;
middle = middle->previous;
memusestr[0] = middle->letter;
memusestr[1] = 0;
if (middle != &storage) {
ColorTextXY(WorkWindow,memusestr,middle->x,middle->y,middle->fcolor,middle->bcolor);
cx = middle->x; cy = middle->y;
}
}
position--; length--; changes = TRUE;
break;
case TAB: tabplace = cx;
tabplace += (tabspace - ((cx-1) % tabspace));
if (tabplace > MAXWIDTH) {
tabplace = MINWIDTH;
cy++;
if (cy > maxheight) cy = maxheight;
}
cx = tabplace;
break;
default: for (tempnum = 0; tempnum < scanner; tempnum++) {
if (Buffer[tempnum] < 32 || Buffer[tempnum] == 127) break;
sdlstptr = lastptr;
lastptr = (struct ANSI *) malloc(sizeof(struct ANSI));
if (lastptr == 0) {
lastptr = sdlstptr;
sdlstptr = lastptr->previous;
break;
}
sdlstptr->next = lastptr;
lastptr->previous = sdlstptr;
lastptr->next = 0;
if (middle->next == lastptr) {
lastptr->letter = Buffer[tempnum];
lastptr->x = cx;
lastptr->y = cy;
lastptr->fcolor = fcolor;
lastptr->bcolor = bcolor;
middle = lastptr;
}
else {
middle = middle->next;
for (back = lastptr, front = back->previous; back != middle; back = back->previous, front = back->previous) {
back->fcolor = front->fcolor;
back->bcolor = front->bcolor;
back->x = front->x;
back->y = front->y;
back->letter = front->letter;
}
middle->letter = Buffer[tempnum];
middle->x = cx;
middle->y = cy;
middle->fcolor = fcolor;
middle->bcolor = bcolor;
}
ColorTextXY(WorkWindow,Buffer,cx,cy,fcolor,bcolor);
cx++;
if (cx > MAXWIDTH) {
cx = MINWIDTH; cy++;
if (cy > maxheight) cy=maxheight;
}
position++; length++;
changes = TRUE;
}
break;
}
}
}
break;
case MENUPICK: MenuAnalyse(code);
break;
}
}
else {
sprintf(memusestr,"P:X=%2d Y=%2d",mx,my);
if (mx < 1 || my < 1) sprintf(memusestr,"P: ");
ColorText(Gads,memusestr,488,1,7,0);
sprintf(memusestr,"C:X=%2d Y=%2d",cx,cy);
ColorText(Gads,memusestr,380,1,7,0);
sprintf(memusestr,"Pos: %5d Len: %5d",position,length);
ColorText(Gads,memusestr,2,1,7,0);
sprintf(memusestr,"ForeC: %2d BackC: %2d",fcolor,bcolor);
ColorText(Gads,memusestr,200,1,fcolor,bcolor);
sprintf(memusestr,"Set:%2d F1=%c F2=%c F3=%c F4=%c F5=%c F6=%c F7=%c F8=%c",presset+1,funckey[presset][0],funckey[presset][1],
funckey[presset][2],funckey[presset][3],funckey[presset][4],funckey[presset][5],
funckey[presset][6],funckey[presset][7]);
ColorText(Gads,memusestr,3,20,7,0);
sprintf(memusestr,"Free Memory:%7d",AvailMem(0));
ColorText(Gads,memusestr,390,20,3,0);
}
if (message = (struct IntuiMessage *) GetMsg(Gads->UserPort)) {
MessageClass = message->Class;
GadgetPtr = (struct Gadget *) message->IAddress;
ReplyMsg(message);
GadgetID = GadgetPtr->GadgetID;
switch (MessageClass) {
case GADGETUP: if (GadgetID == 18) {
BGmode=togglemode();
break;
}
if (GadgetID == 17) {
if (cmode==0) BGmode = TRUE; else BGmode=FALSE;
break;
}
if (BGmode == TRUE) {
if (GadgetID >= 1 && GadgetID <=8) {
bcolor = (USHORT)GadgetID-1;
if (cmode==0) BGmode = FALSE;
}
}
else {
if (GadgetID >= 1 && GadgetID <= 16)
fcolor = (USHORT)GadgetID - 1;
if (cmode==1) BGmode=TRUE;
}
break;
case ACTIVEWINDOW: ActivateWindow(WorkWindow);
break;
default: break;
}
ActivateWindow(WorkWindow);
}
if (mbuttons) {
/**** Move the cursor to (mx,my) ****/;
cx = mx;
cy = my;
if (cx < MINWIDTH) cx = MINWIDTH;
if (cx > MAXWIDTH) cx = MAXWIDTH;
if (cy < MINHEIGHT) cy = MINHEIGHT;
if (cy > maxheight) cy = maxheight;
}
}
}
/* Routine to toggle fore/back mode ... new to 1.4 by Syd L. Bolton */
togglemode()
{
cmode=1-cmode;
if (cmode==0) {
ForeBackText.IText="Back";
FBStickText.IText="Fore";
}
else {
ForeBackText.IText="Fore";
FBStickText.IText="Back";
}
SetAPen(rport,0);
RectFill(rport,553,10,635,28);
RefreshGadgets(&FBStickGadget,Gads,0);
if (cmode==0) return(FALSE); else return(TRUE);
}
#include "config.c"
/************************************************************************
* Now, for the Libraries that need to be opened *
************************************************************************/
OpenLibs()
{
DOSBase = (struct DOSBase *) OpenLibrary("dos.library",0L);
IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0L);
GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L);
if ((DiskfontBase = (struct DiskfontBase *) OpenLibrary("diskfont.library",0))==0) {
CloseLibs("Diskfont Library cannot be found");
exit(FALSE);
}
if ((TFont = (struct TextFont *) OpenDiskFont(&WorkFont)) == 0) {
WorkFont.ta_Name = (STRPTR)"topaz.font";
WorkFont.ta_YSize = TOPAZ_EIGHTY;
}
Cursor.x = -1;
Cursor.y = 10;
Cursor.height = 8;
Spr1 = GetSprite(&Cursor,-1);
if (Spr1 == -1) {
CloseLibs("Sprite cannot be displayed");
exit(FALSE);
}
OpenSAW();
if (!(OpenDevice("console.device",-1L,&ioStdReq,0L))) ConsoleDevice = ioStdReq.io_Device;
else CloseLibs("Could not open console.device");
}
OpenSAW()
{
struct ViewPort *vp;
if (!(WorkScreen = (struct Screen *) OpenScreen(&FirstWorkScreen))) {
CloseLibs("Screen cannot be opened");
exit(FALSE);
}
vp = &WorkScreen->ViewPort;
SetWindowSprite();
LoadRGB4(vp,AtrColors,16);
RemakeDisplay();
FirstWorkWindow.Screen = WorkScreen;
if (!(WorkWindow = (struct Window *) OpenWindow(&FirstWorkWindow))) {
CloseLibs("Window cannot be opened");
exit(FALSE);
}
GadgetWindow.Screen = WorkScreen;
if (!(Gads = (struct Window *) OpenWindow(&GadgetWindow))) {
CloseLibs("Gadget window cannot be opened");
exit(FALSE);
}
rport=Gads->RPort;
if (sclearmode) SClear.Flags |= CHECKED; else Clear.Flags &= ~CHECKED;
if (lacemode) Interlace.Flags |= CHECKED; else Interlace.Flags &= ~CHECKED;
SetMenuStrip(WorkWindow, &Project);
return(0);
}
/************************************************************************
* If Libraries have to be opened, then they have to be closed! *
************************************************************************/
CloseLibs(str)
UBYTE *str;
{
USHORT handle;
FreeAllMem();
if(Spr1 != -1) FreeSprite(Spr1);
CloseSAW();
if(TFont) CloseFont(TFont);
if(DiskfontBase) CloseLibrary(DiskfontBase);
CloseLibrary(GfxBase);
CloseLibrary(IntuitionBase);
CloseLibrary(DOSBase);
if(str[0] != '~') {
handle = Open("RAW:160/50/320/25/Prism",MODE_NEWFILE);
if (handle) {
Write(handle,str,strlen(str));
Delay(120L);
Close(handle);
}
}
}
CloseSAW()
{
if (Gads) CloseWindow(Gads);
if (WorkWindow) {
ClearMenuStrip(WorkWindow);
CloseWindow(WorkWindow);
}
if (WorkScreen) CloseScreen(WorkScreen);
return(0);
}
/*************************************************************************
* The color version of the Text routine *
*************************************************************************/
ColorText(w_ptr,s,x,y,fc,bc)
struct Window *w_ptr;
UBYTE *s;
USHORT x,y;
USHORT fc,bc;
{
GeneralText.FrontPen = (UBYTE) fc;
GeneralText.BackPen = (UBYTE) bc;
GeneralText.IText = (UBYTE *) s;
PrintIText(w_ptr->RPort,&GeneralText,x,y);
return(TRUE);
}
/*************************************************************************
* X and Y now represent the row and column of TEXT and not bits *
*************************************************************************/
ColorTextXY(w_ptr,s,x,y,fc,bc)
struct Window *w_ptr;
UBYTE *s;
USHORT x,y;
USHORT fc,bc;
{
USHORT ix,iy;
GeneralText.FrontPen = (UBYTE) fc;
GeneralText.BackPen = (UBYTE) bc;
GeneralText.IText = (UBYTE *) s;
if (x < MINWIDTH || x > MAXWIDTH || y < MINHEIGHT || y > maxheight) return(FALSE);
ix = (x-1)*8; /* to calculate distance by text size and not pixels */
iy = (y-1)*8;
PrintIText(w_ptr->RPort,&GeneralText,ix,iy);
return(TRUE);
}
/*************************************************************************
* Free the used memory *
*************************************************************************/
FreeAllMem()
{
struct IntuiText ClearingText = {
4,7,JAM2,126,11,0,"Clearing Current ANSI. Please Wait.",0
};
InitRequester(&FileSelectBox);
FileSelectBox.LeftEdge = 50;
FileSelectBox.TopEdge = 85;
FileSelectBox.Width = 540;
FileSelectBox.Height = 30;
FileSelectBox.ReqText = &ClearingText;
FileSelectBox.BackFill = 7;
Request(&FileSelectBox, WorkWindow);
for (lastptr=storage.next; lastptr != 0; lastptr = lastptr->next)
free((UBYTE *)lastptr);
storage.next = 0;
lastptr = &storage;
middle = lastptr;
length = 0; position = 0;
cx = MINWIDTH; cy = MINHEIGHT; changes = FALSE;
EndRequest(&FileSelectBox, WorkWindow);
return(TRUE);
}
/*************************************************************************
* Attempt to playback what what stored in Memory *
*************************************************************************/
PlayBack()
{
UBYTE displaystr[2];
position = length = 0;
ClearWorkWindow();
WindowToFront(WorkWindow);
ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipBlank);
Delay(30L);
displaystr[1] = 0;
if (speed==0) {
for (lastptr=storage.next; lastptr != 0; lastptr = lastptr->next) {
displaystr[0] = lastptr->letter;
ColorTextXY(WorkWindow,displaystr,lastptr->x,lastptr->y, lastptr->fcolor,lastptr->bcolor);
++position;++length;
}
}
else {
for (lastptr=storage.next; lastptr != 0; lastptr = lastptr->next) {
displaystr[0] = lastptr->letter;
ColorTextXY(WorkWindow,displaystr,lastptr->x,lastptr->y, lastptr->fcolor,lastptr->bcolor);
++position;++length;
Delay(speed);
}
}
lastptr = sdlstptr->next;
middle = lastptr;
cx = middle->x; cy = middle->y;
SetWindowSprite();
WindowToBack(WorkWindow);
return(TRUE);
}
/*************************************************************************
* Clear the WorkWindow *
*************************************************************************/
ClearWorkWindow()
{
USHORT i;
static UBYTE blanker[] = " ";
for (i=0; i<=FirstWorkWindow.Height; i+=8)
ColorText(WorkWindow,blanker,0,i,1,0);
return(TRUE);
}
/************************************************************************
* Analyse which item was picked on the menu *
************************************************************************/
MenuAnalyse(Menunumber)
USHORT Menunumber;
{
USHORT Menu, MenuItem, SubItem;
Menu = MENUNUM(Menunumber);
MenuItem = ITEMNUM(Menunumber);
SubItem = SUBNUM(Menunumber);
switch (Menu) {
case 0: ProjectMenu(MenuItem,SubItem);
break;
case 1: SetupMenu(MenuItem,SubItem);
break;
default: break;
}
return(TRUE);
}
ProjectMenu(MenuItem,SubItem)
USHORT MenuItem, SubItem;
{
BOOL GetResponse;
switch (MenuItem) {
case 0: AboutReq();
break;
case 1: PlayBack();
break;
case 2: GetResponse = AreYouSure("Clear Memory?");
if (GetResponse == TRUE) {
if (changes == TRUE) {
GetResponse = AreYouSure("Save new changes?");
if (GetResponse == TRUE) SaveANSI(TRUE);
}
FreeAllMem();
ClearWorkWindow();
}
break;
case 3: LoadANSI(TRUE);
break;
case 4: SaveANSI(TRUE);
break;
case 5: switch(SubItem) { /* APPEND SUBMENUS */
case 0: LoadANSI(FALSE);
break;
case 1: SaveANSI(FALSE);
break;
}
break;
case 6: GetResponse = AreYouSure("Exit Prism?");
if (GetResponse == TRUE) {
if (changes == TRUE) {
GetResponse = AreYouSure("Save new changes?");
if (GetResponse == TRUE) SaveANSI(TRUE);
}
CloseLibs("~");
exit(TRUE);
}
break;
}
return(TRUE);
}
SetupMenu(MenuItem,SubItem)
USHORT MenuItem,SubItem;
{
switch (MenuItem) {
case 0: SelColor3.NextGadget = &SelColor4;
SelColor7.NextGadget = &SelColor8;
switch (SubItem) {
case 0: CloseSAW();
FirstWorkScreen.Depth = 2;
SelColor3.NextGadget = &FBStickGadget;
OpenSAW();
break;
case 1: CloseSAW();
FirstWorkScreen.Depth = 3;
SelColor7.NextGadget = &FBStickGadget;
OpenSAW();
break;
case 2: CloseSAW();
FirstWorkScreen.Depth = 4;
OpenSAW();
break;
default: break;
}
break;
case 1: set_speed(SubItem);
break;
case 2: CloseSAW();
if (FirstWorkScreen.Height==210) {
FirstWorkScreen.Height=420;
FirstWorkScreen.ViewModes=HIRES|SPRITES|LACE;
FirstWorkWindow.Height=400;
maxheight=50;
lacemode=1;
}
else {
FirstWorkScreen.Height=210;
FirstWorkScreen.ViewModes=HIRES|SPRITES;
FirstWorkWindow.Height=200;
maxheight=25;
lacemode=0;
}
OpenSAW();
break;
case 3: sclearmode=1-sclearmode;
if (sclearmode) SClear.Flags |= CHECKED;
else SClear.Flags &= ~CHECKED;
break;
case 4: configure();
break;
default: break;
}
return(TRUE);
}
set_speed(sub)
int sub;
{
switch (sub) {
case 0: TWBaud.Flags |= CHECKED;
TFBaud.Flags &= ~CHECKED;
Fastest.Flags &= ~CHECKED;
speed=2;
break;
case 1: TFBaud.Flags |= CHECKED;
TWBaud.Flags &= ~CHECKED;
Fastest.Flags &= ~CHECKED;
speed=1;
break;
case 2: Fastest.Flags |= CHECKED;
TFBaud.Flags &= ~CHECKED;
TWBaud.Flags &= ~CHECKED;
speed=0;
break;
default: break;
}
}
/************************************************************************
* An "Are You Sure?" Requester *
************************************************************************/
AreYouSure(yousaidit)
UBYTE *yousaidit;
{
BOOL Response;
struct IntuiText Really = {
0,1,JAM1,40,5,0,0,0
};
struct IntuiText Yes = {
0,1,JAM1,5,3,0,"YES",0
};
struct IntuiText No = {
0,1,JAM1,5,3,0,"NO!",0
};
Really.IText = (UBYTE *)yousaidit;
Response = AutoRequest(WorkWindow,&Really,&Yes,&No,0,0,TextLength(WorkWindow->RPort,yousaidit,strlen(yousaidit))+100,50);
return((USHORT)Response);
}
/*************************************************************************
* The "Something Went Wrong" Requester Routine *
*************************************************************************/
GenErrorReq(thecatch)
UBYTE *thecatch;
{
BOOL Answer;
struct IntuiText SomethingText = {
0,1,JAM2,15,8,0,0,0
};
struct IntuiText AlrightText = {
0,1,JAM2,5,3,0,"OK?",0
};
SomethingText.IText = (UBYTE *)thecatch;
Answer = AutoRequest(WorkWindow,&SomethingText,0,&AlrightText,0,0,TextLength(WorkWindow->RPort,thecatch,strlen(thecatch))+100,37);
return((USHORT)Answer);
}
/*************************************************************************
* The "About" Requester Routine *
*************************************************************************/
AboutReq()
{
BOOL Waiting;
UBYTE *LeftMouse = (UBYTE *)0xBFE001;
ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipBlank);
RequesterWindow.LeftEdge = 41;
RequesterWindow.TopEdge = 20;
RequesterWindow.Width = 558;
RequesterWindow.Height = 82;
RequesterWindow.Title = 0;
RequesterWindow.Screen = WorkScreen;
RequesterWindow.FirstGadget = 0;
InitRequester(&FileSelectBox);
FileSelectBox.LeftEdge = 4;
FileSelectBox.TopEdge = 2;
FileSelectBox.Width = 550;
FileSelectBox.Height = 90;
FileSelectBox.ReqText = &AboutProgText;
FileSelectBox.BackFill = 7;
if (!(ReqWindow = (struct Window *) OpenWindow(&RequesterWindow))) {
SetWindowSprite();
return(FALSE);
}
Request(&FileSelectBox, ReqWindow);
Waiting = TRUE;
while (Waiting)
if(!((*LeftMouse & 0x40) == 0x40)) Waiting = FALSE;
EndRequest(&FileSelectBox, ReqWindow);
if (ReqWindow) CloseWindow(ReqWindow);
SetWindowSprite();
return((USHORT)FALSE);
}
/************************************************************************
* Load ANSI from Disk *
* New improved Routine by Chris *
************************************************************************/
LoadANSI(loadtype)
BOOL loadtype;
{
BOOL Answer;
FILE *AnsiFile;
UBYTE c;
UWORD cx = 1, cy = 1;
UWORD *t, *z;
UWORD Col1 = 1, Col2 = 0, Inten=0, flag, sx, sy, a[3];
struct IntuiText LoadingText = {
4,7,JAM2,122,11,0,"Loading ANSI from disk. Please Wait.",0
};
ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipBlank);
if (loadtype == TRUE) Answer = getfile("Load ANSI",path);
else Answer = getfile("Append Load",path);
if (Answer == FALSE) {
SetWindowSprite();
return(FALSE);
}
if (!(AnsiFile = fopen(filename,"r"))) {
GenErrorReq("File can't open for read!");
SetWindowSprite();
return(FALSE);
}
SetPointer(WorkWindow,&BusyPointer,22,16,0,0);
/***** Start Loading *****/
if (loadtype == TRUE) {
FreeAllMem();
ClearWorkWindow();
}
InitRequester(&FileSelectBox);
FileSelectBox.LeftEdge = 50;
FileSelectBox.TopEdge = 85;
FileSelectBox.Width = 540;
FileSelectBox.Height = 30;
FileSelectBox.ReqText = &LoadingText;
FileSelectBox.BackFill = 7;
Request(&FileSelectBox, WorkWindow);
while (!(feof(AnsiFile))) {
c=getc(AnsiFile);
switch(c) {
case ESC: t=a; flag=0; a[0]=0; a[1]=0; a[2]=0;
if (getc(AnsiFile)!='[') break;
do {
c=getc(AnsiFile);
switch (c) {
case ';': t++; break;
case 'm': for (z=a; z<=t; z++) {
if (*z==0) { Col1=7; Col2=0; Inten=0; }
else if (*z==1) Inten=8;
else if (*z>29 && *z<40) Col1=*z-30;
else if (*z>39 && *z<50) Col2=*z-40;
}
flag=1;
break;
case 'H': cy=a[0]; if (cy==0) cy=1; else if (cy>maxheight) cy=maxheight;
cx=a[1]; if (cx==0) cx=1; else if (cx>MAXWIDTH) cx=MAXWIDTH;
flag=1;
break;
case 'J': cx=MINWIDTH; cy=MINHEIGHT; flag=1;
break;
case 's': sx=cx; sy=cy; flag=1;
break;
case 'u': cx=sx; cy=sy; flag=1;
break;
case 'A': if (a[0]==0) a[0]=1;
cy-=a[0]; if (cy<MINHEIGHT) cy=MINHEIGHT;
flag=1;
break;
case 'D': if (a[0]==0) a[0]=1;
cx-=a[0]; if (cx<MINWIDTH) cx=MINWIDTH;
flag=1;
break;
case 'C': if (a[0]==0) a[0]=1;
cx+=a[0]; if (cx>MAXWIDTH) cx=MAXWIDTH;
flag=1;
break;
case 'B': if (a[0]==0) a[0]=1;
cy+=a[0]; if (cy>maxheight) cy=maxheight;
flag=1;
break;
default: *t=(*t << 3) + (*t << 1) + c - '0';
break;
}
} while (flag==0);
break;
case LINEFEED: cx = MINWIDTH;
cy++;
if (cy > maxheight) cy = maxheight;
break;
default: if (c < 32 || c == 127) break;
sdlstptr = lastptr;
lastptr = (struct ANSI *) malloc(sizeof(struct ANSI));
if (lastptr == 0) break;
middle = lastptr;
sdlstptr->next = lastptr;
lastptr->previous = sdlstptr;
lastptr->next = 0;
lastptr->letter = c;
lastptr->x = cx;
lastptr->y = cy;
lastptr->fcolor = Col1+Inten;
lastptr->bcolor = Col2;
if (++cx > MAXWIDTH) {
cx = MINWIDTH;
if (++cy > maxheight) cy=maxheight;
}
break;
}
}
fclose(AnsiFile);
EndRequest(&FileSelectBox, WorkWindow);
ClearPointer(WorkWindow);
PlayBack();
SetWindowSprite();
return(TRUE);
}
/************************************************************************
* Save ANSI to disk *
* New improved routine by Chris *
************************************************************************/
SaveANSI(savetype)
BOOL savetype;
{
BOOL Answer;
FILE *AnsiFile;
UBYTE Inten, Fore, Back, linelength, X, Y;
UBYTE OldInten=0, OldFore=7, OldBack=0, OldX=1, OldY=1;
UBYTE Line[41], savetypechr[2];
struct IntuiText SavingText = {
4,7,JAM2,134,11,0,"Saving ANSI to disk. Please Wait.",0
};
ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipBlank);
if (savetype == TRUE) {
savetypechr[0] = 'w';
savetypechr[1] = 0;
Answer = stdfile("Save ANSI",0,"#?",filename,WorkScreen);
}
else {
savetypechr[0] = 'a';
savetypechr[1] = 0;
Answer = stdfile("Append Save ANSI",0,"#?",filename,WorkScreen);
}
if (Answer == FALSE) {
SetWindowSprite();
return(FALSE);
}
if (!(AnsiFile = fopen(filename,savetypechr))) {
GenErrorReq("File can't open for write!");
SetWindowSprite();
return(FALSE);
}
SetPointer(WorkWindow,&BusyPointer,22,16,0,0);
/***** Start Saving *****/
InitRequester(&FileSelectBox);
FileSelectBox.LeftEdge = 50;
FileSelectBox.TopEdge = 85;
FileSelectBox.Width = 540;
FileSelectBox.Height = 30;
FileSelectBox.ReqText = &SavingText;
FileSelectBox.BackFill = 7;
Request(&FileSelectBox, WorkWindow);
if (sclearmode) fprintf(AnsiFile,"%c[0m%c[H%c[J",ESC,ESC,ESC);
linelength = 10;
for (lastptr=storage.next; lastptr != 0; lastptr = lastptr->next) {
Fore=lastptr->fcolor; Back=lastptr->bcolor; Inten=Fore&8; Fore&=7; X=lastptr->x; Y=lastptr->y;
/***** Check for color changes *****/
if (Inten!=OldInten) {
if (Inten==0) {
if (Fore==7) {
if (Back==0) sprintf(Line, "%c[0m", ESC);
else sprintf(Line, "%c[0;4%dm", ESC, Back);
}
else {
if (Back==0) sprintf(Line, "%c[0;3%dm", ESC, Fore);
else sprintf(Line, "%c[0;3%d;4%dm", ESC, Fore, Back);
}
}
else {
if (Fore==OldFore) {
if (Back==OldBack) sprintf(Line, "%c[1m", ESC);
else sprintf(Line, "%c[1;4%dm", ESC, Back);
}
else {
if (Back==OldBack) sprintf(Line, "%c[1;3%dm", ESC, Fore);
else {
if (Fore==7) sprintf(Line, "%c[0;1;4%dm", ESC, Back);
else if (Back==0) sprintf(Line, "%c[0;1;3%dm", ESC, Fore);
else sprintf(Line, "%c[1;3%d;4%dm", ESC, Fore, Back);
}
}
}
}
else { /* no change in inten */
if (Back!=OldBack) {
if (Fore!=OldFore) sprintf(Line, "%c[3%d;4%dm", ESC, Fore, Back);
else sprintf(Line, "%c[4%dm", ESC, Back);
}
else if (Fore!=OldFore) sprintf(Line, "%c[3%dm", ESC, Fore);
else Line[0]=0;
}
if (Line[0]) {
linelength += strlen(Line);
if ((linelength+1) >= 80) {
fprintf(AnsiFile,"%c[s%c%c[u",ESC,RETURN,ESC);
linelength = 3 + strlen(Line);
}
fprintf(AnsiFile,"%s",Line);
}
/***** Check for position changes *****/
if (X!=OldX) {
if (Y!=OldY) sprintf(Line, "%c[%d;%dH", ESC, Y, X);
else {
if (X==OldX+1) sprintf(Line, "%c[C", ESC);
else if (X>OldX) sprintf(Line, "%c[%dC", ESC, X-OldX);
else if (X==OldX-1) sprintf(Line, "%c[D", ESC);
else if (X<OldX) sprintf(Line, "%c[%dD", ESC, OldX-X);
}
}
else {
if (Y==OldY) Line[0]=0;
else {
if (Y==OldY+1) sprintf(Line, "%c[B", ESC);
else if (Y>OldY) sprintf(Line, "%c[%dB", ESC, Y-OldY);
else if (Y==OldY-1) sprintf(Line, "%c[A", ESC);
else if (Y<OldY) sprintf(Line, "%c[%dA", ESC, OldY-Y);
}
}
if (Line[0]) {
linelength += strlen(Line);
if ((linelength+1) >= 80) {
fprintf(AnsiFile,"%c[s%c%c[u",ESC,RETURN,ESC);
linelength = 3 + strlen(Line);
}
fprintf(AnsiFile,"%s",Line);
}
/***** Print the actual character *****/
if ((linelength+1) >= 80) {
fprintf(AnsiFile,"%c[s%c%c[u",ESC,RETURN,ESC);
linelength = 3;
}
fprintf(AnsiFile,"%c",lastptr->letter);
linelength++;
if (++X>MAXWIDTH) {
X=MINWIDTH;
if (++Y > maxheight) Y=maxheight;
}
OldInten=Inten; OldFore=Fore; OldBack=Back; OldX=X; OldY=Y;
}
lastptr = sdlstptr->next;
fclose(AnsiFile);
changes = FALSE;
EndRequest(&FileSelectBox, WorkWindow);
ClearPointer(WorkWindow);
SetWindowSprite();
return(TRUE);
}
SetWindowSprite()
{
if (FirstWorkWindow.Height==200) {
Cursor.height=8;
ChangeSprite(&WorkScreen->ViewPort,&Cursor,NormalCursor);
}
else {
Cursor.height=4;
ChangeSprite(&WorkScreen->ViewPort,&Cursor,InterlaceCursor);
}
}
getfile(titl,path)
char *titl,*path;
{
windowtopedge=WorkWindow->TopEdge;
windowleftedge=WorkWindow->LeftEdge;
while(stdfile(titl, filename, path, filename, WorkScreen)) {
BPTR stdlock;
struct FileInfoBlock *stdfib;
FILE *fp;
int c;
stdfib = AllocMem(sizeof(struct FileInfoBlock), MEMF_PUBLIC);
if (!stdfib) {
GenErrorReq("Out of memory!\n");
break;
}
if (!(stdlock = Lock(filename, ACCESS_READ))) {
GenErrorReq("Can't obtain lock.");
FreeMem(stdfib, sizeof(struct FileInfoBlock));
continue;
}
if (!(Examine(stdlock, stdfib))) {
GenErrorReq("Can't examine file");
UnLock(stdlock);
FreeMem(stdfib, sizeof(struct FileInfoBlock));
continue;
}
UnLock(stdlock);
if(stdfib->fib_DirEntryType >= 0) {
GenErrorReq("That is a directory!");
FreeMem(stdfib, sizeof(struct FileInfoBlock));
continue;
}
FreeMem(stdfib, sizeof(struct FileInfoBlock));
fclose(fp);
return(TRUE);
break;
}
return(FALSE);
}
load_config()
{
FILE *fp;
int i;
if (!(fp=fopen("prism.cfg","r")))
return();
fgets(path,80,fp);
if(!(strcmp(path,"VER1\n"))) {
fgets(path,30,fp);
for (i=0; i<30; i++)
if (path[i]=='\n') path[i]='\0';
strcpy(WorkFont.ta_Name,path);
fscanf(fp,"%d %d %d %d %d %d",&speed,&maxcolor,&read_dir,&lacemode,&sclearmode,&tabspace);
if (sclearmode==0) SClear.Flags &= ~CHECKED;
if (lacemode) {
FirstWorkScreen.Height=420;
FirstWorkScreen.ViewModes=HIRES|SPRITES|LACE;
FirstWorkWindow.Height=400;
maxheight=50;
}
switch(speed) {
case 1: Fastest.Flags &= ~CHECKED;
TFBaud.Flags |= CHECKED;
break;
case 2: Fastest.Flags &= ~CHECKED;
TWBaud.Flags |= CHECKED;
break;
default: break;
}
switch(maxcolor) {
case 15: FirstWorkScreen.Depth=4;
break;
case 7: FirstWorkScreen.Depth=3;
Forplanes.Flags &= ~CHECKED;
Threeplanes.Flags |= CHECKED;
SelColor7.NextGadget = &FBStickGadget;
break;
case 3: FirstWorkScreen.Depth=2;
Forplanes.Flags &= ~CHECKED;
Twoplanes.Flags |= CHECKED;
SelColor3.NextGadget = &FBStickGadget;
break;
default: break;
}
}
fclose(fp);
path[0]='\0';
}